package com.net.xpay.stat.scheduler;

import com.net.xpay.stat.task.UserTransStatDailyTask;
import com.net.xpay.common.helper.NoticeHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 net
 * @description: 用户转账金额和次数定时任务
net
 * @create: 2020-09-09 22:45
 **/
@Slf4j
@Component
public class UserTransStatScheduler {

    @Autowired
    private UserTransStatDailyTask userTransStatDailyTask;

    @Autowired
    private NoticeHelper noticeHelper;

    @Scheduled(cron = "0 30 0 * * *")
    public void doUserTransStatDailyTask() {
        try {
            long t1 = System.currentTimeMillis();
            log.info("start schedule doUserTransStatDailyTask|now={}", LocalDateTime.now());
            userTransStatDailyTask.startDailyWork();
            long t2 = System.currentTimeMillis();
            log.info("end schedule doUserTransStatDailyTask|now={}|cost={}", LocalDateTime.now(), t2 - t1);
            noticeHelper.sendSystemInfoNotice("用户转账金额和次数统计完成，耗费时间：" + (t2 - t1), "text");
        } catch (Throwable e) {
            log.warn("doUserTransStatDailyTask error", e);
            noticeHelper.sendSystemMonitorNotice("用户转账金额和次数统计失败|doUserTransStatDailyTask error", "text");
        }
    }

}